package com.springloadfactory;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.serviceloader.ServiceFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

/**
 * @author fanxiao  2022/2/17
 * @since 1.0.0
 */
@Configuration
public class AppConfig {

	@Bean("serviceFactoryBean")
	public ServiceFactoryBean serviceFactoryBean(){
		ServiceFactoryBean factoryBean = new ServiceFactoryBean();
		factoryBean.setServiceType(Eoo.class);
		return factoryBean;
	}

	@Bean("serviceFactoryBeanFoo")
	public ServiceFactoryBean serviceFactoryBeanFoo(){
		ServiceFactoryBean factoryBean = new ServiceFactoryBean();
		factoryBean.setServiceType(Foo.class);
		return factoryBean;
	}


//	@Bean("eooProvider")
//	public Eoo eoo(@Qualifier("serviceFactoryBean") ServiceFactoryBean serviceFactoryBean) throws Exception{
//		Eoo eoo = (Eoo) serviceFactoryBean.getObject();
//		return eoo;
//	}



	@Bean("fooProvider")
	public Foo foo(@Qualifier("serviceFactoryBeanFoo") ServiceFactoryBean serviceFactoryBean) throws Exception{
		Foo foo = (Foo) serviceFactoryBean.getObject();
		return foo;
	}

	@Bean
	public static LoadFactoryBeanFactoryPostProcessor loadFactoryBeanFactoryPostProcessor(){
		return new LoadFactoryBeanFactoryPostProcessor();
	}
}